package org.jypj.dev.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.jypj.dev.model.StationWeather;
import org.jypj.dev.util.StringUtil;
import org.springframework.stereotype.Service;
import org.jypj.dev.dao.IStationWeatherDao;
import org.jypj.dev.service.IStationWeatherService;
import org.jypj.dev.util.Page;

@Service("roadWeatherService")
public class StationWeatherServiceImpl implements IStationWeatherService {

    @Resource
    private IStationWeatherDao stationWeatherDao;

    /**
     * 保存
     * 所有字段全都保存
     *
     * @param stationWeather
     * @return 保存后的对象包括ID
     */
    public int saveStationWeather(StationWeather stationWeather) {
        if (StringUtil.isEmpty(stationWeather.getId())) {
            String uuid = UUID.randomUUID().toString().replace("-", "").trim();
            stationWeather.setId(uuid);
        }
        return stationWeatherDao.saveStationWeather(stationWeather);
    }

    @Override
    public int saveStationWeathers(List<StationWeather> stationWeathers) {

        return stationWeatherDao.saveStationWeathers(stationWeathers);
    }

    /**
     * 根据ID删除
     *
     * @param id 主键ID
     * @return 删除记录数
     */
    public int deleteStationWeatherById(String id) {

        return stationWeatherDao.deleteStationWeatherById(id);
    }

    /**
     * 根据对象删除
     *
     * @param stationWeather
     * @return
     */
    public int deleteStationWeatherByObject(StationWeather stationWeather) {

        return stationWeatherDao.deleteStationWeatherByObject(stationWeather);
    }

    /**
     * 更新
     * 更新所有字段
     *
     * @param stationWeather
     * @return 保存后的对象包括ID
     */
    public int updateStationWeather(StationWeather stationWeather) {

        return stationWeatherDao.updateStationWeather(stationWeather);
    }

    /**
     * 按ID查询
     *
     * @return StationWeather
     * @parm id 主键ID
     */
    public StationWeather selectStationWeatherById(String id) {

        return stationWeatherDao.selectStationWeatherById(id);
    }

    /**
     * 分页查询 包含条件
     *
     * @param page 分页对象
     * @param map  查询条件
     * @return List<StationWeather>
     */
    public Page selectOnePageByMap(Page page, Map<String, Object> map) {
        List<StationWeather> stationWeathers = stationWeatherDao.selectOnePageByMap(page, map);
        if (stationWeathers != null && stationWeathers.size() > 0) {
            page.setResult(stationWeathers);
        } else {
            page.setResult(new ArrayList<StationWeather>());
        }
        return page;
    }

    /**
     * 分页查询 包含对象条件
     *
     * @param page           分页对象
     * @param stationWeather 查询条件
     * @return Page
     */
    public Page selectOnePageByStationWeather(Page page, StationWeather stationWeather) {
        List<StationWeather> stationWeathers = stationWeatherDao.selectOnePageByStationWeather(page, stationWeather);
        if (stationWeathers != null && stationWeathers.size() > 0) {
            page.setResult(stationWeathers);
        } else {
            page.setResult(new ArrayList<StationWeather>());
        }
        return page;
    }

    /**
     * 按条件查询全部的
     *
     * @param map 查询条件
     * @return List<StationWeather>
     */
    public List<StationWeather> selectAllByMap(Map<String, Object> map) {
        return stationWeatherDao.selectAllByMap(map);
    }


    /**
     * 按条件查询全部的
     *
     * @param stationWeather 查询条件
     * @return List<StationWeather>
     */
    public List<StationWeather> selectAllByStationWeather(StationWeather stationWeather) {

        return stationWeatherDao.selectAllByStationWeather(stationWeather);
    }

    /**
     * 按条件查询单个对象
     *
     * @param map 查询条件
     * @return StationWeather
     */
    public StationWeather selectObjectByMap(Map<String, Object> map) {

        return stationWeatherDao.selectObjectByMap(map);
    }

    /**
     * 按条件查询单个对象
     *
     * @param stationWeather 查询条件
     * @return StationWeather
     */
    public StationWeather selectObjectByStationWeather(StationWeather stationWeather) {

        return stationWeatherDao.selectObjectByStationWeather(stationWeather);
    }
}